package com.liwang.lanouhn.nvshengo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.liwang.lanouhn.nvshengo.Info.ContributeInfo;
import com.liwang.lanouhn.nvshengo.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by lanouhn on 2016/10/24.
 */
public class ContributeAdapter extends RecyclerView.Adapter<ContributeAdapter.ContributeViewHolder> {
    private Context context;
    private List<ContributeInfo> contributeInfos;

    public ContributeAdapter(Context context, List<ContributeInfo> contributeInfos) {
        this.context = context;
        this.contributeInfos = contributeInfos;
    }

    @Override
    public ContributeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_contribute, null);
        ContributeViewHolder holder = new ContributeViewHolder(view);
        return holder;

    }

    @Override
    public void onBindViewHolder(ContributeViewHolder holder, int position) {
        ContributeInfo info = contributeInfos.get(position);
        if (position < 3) {
            holder.tv_rank.setTextColor(context.getResources().getColor(R.color.lowyellow));
        } else {
            holder.tv_rank.setTextColor(context.getResources().getColor(R.color.lowblack));
        }
        holder.tv_rank.setText((position + 1) + "");
        Picasso.with(context).load(info.getAvatar()).into(holder.iv_head);
        holder.tv_username.setText(info.getUserName());
        holder.tv_consume.setText(info.getCount() + "");

    }

    @Override
    public int getItemCount() {
        return contributeInfos.size();
    }

    public class ContributeViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public TextView tv_rank;
        public CircleImageView iv_head;
        public TextView tv_username;
        public TextView tv_consume;

        public ContributeViewHolder(View itemView) {
            super(itemView);
            tv_rank = (TextView) itemView.findViewById(R.id.tv_rank);
            iv_head = (CircleImageView) itemView.findViewById(R.id.iv_head);
            tv_username = (TextView) itemView.findViewById(R.id.tv_username);
            tv_consume = (TextView) itemView.findViewById(R.id.tv_consume);
        }

    }
}

